home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 7.3 KB | 318 lines | [TEXT/MPS ] |
- /*
- File: TupleDatabase.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __TUPLEDATABASE__
- #include "TupleDatabase.h"
- #endif
-
- #ifndef __STRING__
- #include "String.h"
- #endif
-
- #ifndef __DEBUGASSERT__
- #include "DebugAssert.h"
- #endif
-
- #ifndef __DEBUGCONSTANTS__
- #include "DebugConstants.h"
- #endif
-
- #pragma segment ATupleDatabase
-
- class TDebugFlag;
- extern TDebugFlag chrisFlag;
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- long
- ATupleKey::Compare ( const AComparable& other ) const
- {
- const ATupleKey& that = (ATupleKey&) other;
- return ::CompareBuffers ( GetData (), GetLength (), that.GetData (), that.GetLength () );
- }
-
- /***********************************|****************************************/
-
- unsigned long
- ATupleKey::SetData ( const char* string )
- {
- return SetData ( string, strlen ( string ) );
- }
-
- /***********************************|****************************************/
-
- unsigned long
- ATupleKey::SetData ( const void* buffer, unsigned long requestedLength )
- {
- unsigned long actualLength = SetLength ( requestedLength );
- unsigned long copiedLength = Minimum ( requestedLength, actualLength );
- BlockMove ( (Ptr) buffer, (Ptr) GetData (), (Size) copiedLength );
- return copiedLength;
- }
-
- /***********************************|****************************************/
-
- #ifndef __FSTREAM__
- #include "FStream.h"
- #endif
-
- extern ostream& DumpHex (ostream& s, const void* p, unsigned long size);
-
- ostream&
- ATupleKey::operator >> ( ostream& stream ) const
- {
- if ( chrisFlag.Flag ( kExtensiveTupleKeyDescribe ) )
- {
- stream << "ATupleKey @ " << (void*) this << "\n";
- stream << "\tGetLength (): " << GetLength () << "\n";
- stream << "\tGetData (): " << (void*) GetData () << "\n";
- DumpHex ( stream, GetData (), GetLength () );
- }
- else
- {
- stream << "\""; stream.write ( (char*) GetData (), GetLength() ) << "\"";
- }
-
- return stream;
- }
-
- /***********************************|****************************************/
-
- ATupleDatabase::ATupleDatabase()
- {
- }
-
- /***********************************|****************************************/
-
- ATupleDatabase::~ATupleDatabase()
- {
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- ATupleKey::ATupleKey ():
- AComparable ()
- {
- }
-
- /***********************************|****************************************/
-
- ATupleKey::~ATupleKey ()
- {
- }
-
- /***********************************|****************************************/
-
- CFourByteKey::CFourByteKey ():
- ATupleKey (),
- fData ( 0 )
- {
- }
-
- /***********************************|****************************************/
-
- CFourByteKey::CFourByteKey ( long value ):
- ATupleKey (),
- fData ( (unsigned long) value )
- {
- }
-
- /***********************************|****************************************/
-
- CFourByteKey::CFourByteKey ( unsigned long value ):
- ATupleKey (),
- fData ( value )
- {
- }
-
- /***********************************|****************************************/
-
- CFourByteKey::CFourByteKey ( const void* value ):
- ATupleKey (),
- fData ( (unsigned long) value )
- {
- }
-
- /***********************************|****************************************/
-
- CFourByteKey::~CFourByteKey ()
- {
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- CTupleKey::CTupleKey ():
- ATupleKey (),
- fBuffer ( 0 )
- {
- fBuffer.ZeroBuffer ();
- }
-
- /***********************************|****************************************/
-
- CTupleKey::CTupleKey ( unsigned long length ):
- ATupleKey (),
- fBuffer ( length )
- {
- fBuffer.ZeroBuffer ();
- }
-
- /***********************************|****************************************/
-
- CTupleKey::CTupleKey ( const ATupleKey& that ):
- ATupleKey (),
- fBuffer ( that.GetData (), that.GetLength () )
- {
- }
-
- /***********************************|****************************************/
-
- CTupleKey::CTupleKey ( const char* string ):
- ATupleKey (),
- fBuffer ( string, strlen ( string ) )
- {
- }
-
- /***********************************|****************************************/
-
- CTupleKey::CTupleKey ( const StringPtr string, Boolean includeLengthByte ):
- ATupleKey (),
- fBuffer ( includeLengthByte ? (char*) string : (char*) string + 1, includeLengthByte ? string [ 0 ] + 1 : string [ 0 ] )
- {
- }
-
- /***********************************|****************************************/
-
- CTupleKey::CTupleKey ( const void* data, unsigned long length ):
- ATupleKey (),
- fBuffer ( data, length )
- {
- }
-
- /***********************************|****************************************/
-
- CTupleKey::~CTupleKey ()
- {
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- unsigned long
- CFourByteKey::SetLength ( unsigned long length )
- {
- ASSERT ( length == sizeof ( fData ) );
- return sizeof ( fData );
- }
-
- /***********************************|****************************************/
-
- long
- CFourByteKey::Compare ( const AComparable& other ) const
- {
- ASSERT ( sizeof ( fData ) == ( (const CFourByteKey&) other ).GetLength () );
- return (long) fData - *(long*) ( (const CFourByteKey&) other ).GetData ();
- }
-
- /***********************************|****************************************/
-
- ostream&
- CFourByteKey::operator >> ( ostream& s ) const
- {
- if ( chrisFlag.Flag ( kExtensiveTupleKeyDescribe ) )
- return ATupleKey::operator >> ( s );
- else
- return s << hexo << fData;
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- void
- ATupleDatabase::Flush ()
- {
- }
-
- /***********************************|****************************************/
-
- ostream&
- ATupleDatabase::operator >> ( ostream& s ) const
- {
- s << "ATupleDatabase @ " << (void*) this << '\n';
-
- unsigned long count = CountTuples ();
- s << "\tCountTuples(): " << count << '\n';
-
- if ( chrisFlag.Flag ( kExtensiveTupleDBDescribe ) )
- {
- CTupleKey key;
- CDataItem data;
-
- for ( unsigned long index = 1; index <= count; index++ )
- {
- if ( ( (ATupleDatabase*) this )->GetTuple ( index, key, data ) )
- {
- s << key << ", " << data << '\n';
- }
- else
- {
- s << "\tFailed to GetTuple ( " << index << " )\n";
- }
- }
- }
-
- return s;
- }
-
- /***********************************|****************************************/
-
- Boolean
- ATupleDatabase::GetTuple ( unsigned long index, ATupleKey& key, ADataItem& data )
- {
- if ( GetTupleKey ( index, key ) )
- return GetTupleData ( key, data );
- else
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean
- ATupleDatabase::GetTupleData ( unsigned long index, ADataItem& data )
- {
- CTupleKey key;
-
- if ( GetTupleKey ( index, key ) )
- return GetTupleData ( key, data );
- else
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean
- ATupleDatabase::SetTuple ( unsigned long index, const ADataItem& data )
- {
- CTupleKey key;
-
- if ( GetTupleKey ( index, key ) )
- return SetTuple ( key, data );
- else
- return false;
- }
-
- /***********************************|****************************************/
-